<?php
$baseurl = JURI::base();
$db = JFactory::getDbo();

$id = 3;
$sql = $db->getQuery(true);
$sql->select("params,note");
$sql->from("#__categories");
$sql->where("id=".$id);
$db->setQuery($sql);
$thisRow = $db->loadObject();
$obj = json_decode($thisRow->params);

$query = $db->getQuery(true);
$query->select("id,title");
$query->from("#__categories");
$query->where("parent_id=".$id);
$query->order("rgt ASC, id DESC LIMIT 0,3");
$db->setQuery($query);
$rows = $db->loadObjectList();
?>
<div class="widget" id="tabvanilla">
	<ul class="tabnav ui-tabs-nav">
		<?php
		$i=0;
		foreach ($rows as $row) {
			$i++;
			if ($i == 1) $selected = 'ui-tabs-selected'; else $selected = '';
			?>
			<li class="<?php echo $selected;?>"><a href="#tab_<?php echo $row->id;?>"><?php echo $row->title;?></a></li>
			<?php
		} 
		?>
    </ul>
    <?php
    $i=0;
	foreach ($rows as $row) {
		$i++;
		if ($i == 1) $show_hide = ''; else $show_hide = ' ui-tabs-hide';
		$sql = $db->getQuery(true);
		$sql->select("id,title,introtext");
		$sql->from("#__content");
		$sql->where("state=1 AND catid=".$row->id);
		$sql->order("ordering ASC, id DESC LIMIT 0,3");
		$sql->limit("0,3");
		$db->setQuery($sql);
		$lsContent = $db->loadObjectList();
		?>
		<div class="tabdiv ui-tabs-panel<?php echo $show_hide;?>" id="tab_<?php echo $row->id;?>" style="">
                <ul>
                	<?php
                	$j=0;
                	foreach ($lsContent as $content) {
                		$j++;
                		if ($j%2==0) $class = ' class="row2"'; else $class = '';
                		$link = JRoute::_("index.php?option=com_content&view=article&id=".$content->id);
                		?>
                		<li<?php echo $class;?>>
                			<a href="<?php echo $link;?>"><?php echo $content->title;?></a>
                			<div class="clearfix"></div>
                			<div><?php echo $content->introtext;?></div>
                		</li>
                		<div class="clearfix"></div>
                		<?php
                	} 
                	?>
                </ul>
	     </div>
     <?php }?>
</div>
<?php
if (!empty($obj->{'image'})){
	?>
	<div class="adver">
		<a href="<?php echo $thisRow->note;?>" target="_blank">
		<img src="<?php echo $baseurl.$obj->{'image'};?>" border="0" />
		</a>
	</div>
	<?php
}
?>

<?php
$id = 4;

$sql = $db->getQuery(true);
$sql->select("params,note");
$sql->from("#__categories");
$sql->where("id=".$id);
$db->setQuery($sql);
$thisRow2 = $db->loadObject();
$obj2 = json_decode($thisRow2->params);

$query = $db->getQuery(true);
$query->select("id,title");
$query->from("#__categories");
$query->where("parent_id=".$id);
$query->order("rgt ASC, id DESC LIMIT 0,3");
$db->setQuery($query);
$rows2 = $db->loadObjectList();
?>
<div class="widget" id="tabvanilla2">
	<ul class="tabnav ui-tabs-nav">
		<?php
		$i=0;
		foreach ($rows2 as $row) {
			$i++;
			if ($i == 1) $selected = 'ui-tabs-selected'; else $selected = '';
			?>
			<li class="<?php echo $selected;?>"><a href="#tab_<?php echo $row->id;?>"><?php echo $row->title;?></a></li>
			<?php
		} 
		?>
    </ul>
    <?php
    $i=0;
	foreach ($rows2 as $row) {
		$i++;
		if ($i == 1) $show_hide = ''; else $show_hide = ' ui-tabs-hide';
		$sql = $db->getQuery(true);
		$sql->select("id,title,introtext");
		$sql->from("#__content");
		$sql->where("state=1 AND catid=".$row->id);
		$sql->order("ordering ASC, id DESC");
		$sql->limit("0,3");
		$db->setQuery($sql);
		$lsContent = $db->loadObjectList();
		?>
		<div class="tabdiv ui-tabs-panel<?php echo $show_hide;?>" id="tab_<?php echo $row->id;?>" style="">
                <ul>
                	<?php
                	$j=0;
                	foreach ($lsContent as $content) {
                		$j++;
                		if ($j%2==0) $class = ' class="row2"'; else $class = '';
                		$link = JRoute::_("index.php?option=com_content&view=article&id=".$content->id);
                		?>
                		<li<?php echo $class;?>>
                			<a href="<?php echo $link;?>"><?php echo $content->title;?></a>
                			<div class="clearfix"></div>
                			<div><?php echo $content->introtext;?></div>
                		</li>
                		<div class="clearfix"></div>
                		<?php
                	} 
                	?>
                </ul>
	     </div>
     <?php }?>
</div>
<?php
if (!empty($obj2->{'image'})){
	?>
	<div class="adver">
		<embed height="80" width="557" name="plugin" src="<?php echo $this->baseurl ?>/images/54vn.swf" type="application/x-shockwave-flash">
	</div>
	<?php
}
?>

<?php
$id = 5;

$sql = $db->getQuery(true);
$sql->select("params,note");
$sql->from("#__categories");
$sql->where("id=".$id);
$db->setQuery($sql);
$thisRow3 = $db->loadObject();
$obj3 = json_decode($thisRow3->params);

$query = $db->getQuery(true);
$query->select("id,title");
$query->from("#__categories");
$query->where("parent_id=".$id);
$query->order("rgt ASC, id DESC LIMIT 0,3");
$db->setQuery($query);
$rows3 = $db->loadObjectList();
?>
<div class="widget" id="tabvanilla3">
	<ul class="tabnav ui-tabs-nav">
		<?php
		$i=0;
		foreach ($rows3 as $row) {
			$i++;
			if ($i == 1) $selected = 'ui-tabs-selected'; else $selected = '';
			?>
			<li class="<?php echo $selected;?>"><a href="#tab_<?php echo $row->id;?>"><?php echo $row->title;?></a></li>
			<?php
		} 
		?>
    </ul>
    <?php
    $i=0;
	foreach ($rows3 as $row) {
		$i++;
		if ($i == 1) $show_hide = ''; else $show_hide = ' ui-tabs-hide';
		$sql = $db->getQuery(true);
		$sql->select("id,title,introtext");
		$sql->from("#__content");
		$sql->where("state=1 AND catid=".$row->id);
		$sql->order("ordering ASC, id DESC");
		$sql->limit("0,3");
		$db->setQuery($sql);
		$lsContent = $db->loadObjectList();
		?>
		<div class="tabdiv ui-tabs-panel<?php echo $show_hide;?>" id="tab_<?php echo $row->id;?>" style="">
                <ul>
                	<?php
                	$j=0;
                	foreach ($lsContent as $content) {
                		$j++;
                		if ($j%2==0) $class = ' class="row2"'; else $class = '';
                		$link = JRoute::_("index.php?option=com_content&view=article&id=".$content->id);
                		?>
                		<li<?php echo $class;?>>
                			<a href="<?php echo $link;?>"><?php echo $content->title;?></a>
                			<div class="clearfix"></div>
                			<div><?php echo $content->introtext;?></div>
                		</li>
                		<div class="clearfix"></div>
                		<?php
                	} 
                	?>
                </ul>
	     </div>
     <?php }?>
</div>
<?php
if (!empty($obj3->{'image'})){
	?>
	<div class="adver">
		<a href="<?php echo $thisRow3->note;?>" target="_blank">
		<img src="<?php echo $baseurl.$obj3->{'image'};?>" border="0" />
		</a>
	</div>
	<?php
}
?>
<script>
$(document).ready(function() {
	$('#tabvanilla > ul').tabs({ fx: { height: 'toggle', opacity: 'toggle' } });
	$('#tabvanilla2 > ul').tabs({ fx: { height: 'toggle', opacity: 'toggle' } });
	$('#tabvanilla3 > ul').tabs({ fx: { height: 'toggle', opacity: 'toggle' } });
	$('#featuredvid > ul').tabs();
});
</script>